package cn.tedu.note.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.tedu.note.entity.Note;
import cn.tedu.note.service.NoteService;
import cn.tedu.note.util.JsonResult;

@Controller
@RequestMapping("/note")
public class NoteController 
	extends AbstractController{
	
	@Resource
	private NoteService noteService;
	
	@RequestMapping("/list.do")
	@ResponseBody
	public JsonResult list(
		String notebookId){
		List<Map<String, Object>> list=
			noteService.listNotes(notebookId);
		return new JsonResult(list);
	}
	
	
	@RequestMapping("/get.do")
	@ResponseBody
	public JsonResult get(String noteId){
		return new JsonResult(
			noteService.getNote(noteId)); 
	}
	
	@RequestMapping("/save.do")
	@ResponseBody
	public JsonResult save(
			String id, String title, 
			String body){
		//检查参数
		Boolean b = noteService.saveNote(
				id, title, body);
		return new JsonResult(b);
	}
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonResult add(String userId, 
			String notebookId,
			String title){
		Thread t = Thread.currentThread();
		System.out.println(t.getName());
		Note note = noteService.addNote(
			notebookId, userId, title);
		return new JsonResult(note);
	}
}






